package com.jiaai.web.common;
import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.auth.api.IOautoApi;
import com.jiaai.auth.model.AccessToken;
import com.jiaai.exception.ServerException;
import com.jiaai.util.RestResultGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title TokenConteller
 * @since 2017/10/11
 */
@RestController
@RequestMapping("/token")
public class TokenConteller {
    private  static Logger logger= LoggerFactory.getLogger(TokenConteller.class);
    @Reference
    private IOautoApi oautoApi;

    /**
     *
     * 生成token
     * @param memberId
     * @return
     * @throws ServerException
     */
    @GetMapping("/get")
    public  Object getToken(String memberId)throws ServerException{
        AccessToken token=null;
        try {
             token= oautoApi.getTokenByMemberId(memberId);
             return RestResultGenerator.genSuccessResult(token);
        } catch (Exception e) {
            logger.error("{},生成token失败error:{}",memberId,e.getMessage());
            return RestResultGenerator.genErrorResult("生成token失败");
        }
    }

}
